<?php
/**
 * 用户管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$tableID = $_GET['tableID'];
$idObj = $_GET['idObj'];
$nameObj = $_GET['nameObj'];
$page = $_GET['pid'] ? $_GET['pid'] : '1';
//用户选择弹出窗口
if ($tableID == 'user') {
	$Users_Model = new Users_Model();

	$tel = isset($_REQUEST['tel']) ? $_REQUEST['tel'] : '';

	$sqlSegment .= ' ORDER BY buildtime DESC ';
	$pwd = '用户选择';
	$addUrl1 = $tel ? "tel={$tel}&" : '';
	$addUrl2 = $idObj ? "idObj={$idObj}&" : ''	;
	$addUrl3 = $nameObj ? "nameObj={$nameObj}&" : '';
	$addUrl=$addUrl1.$addUrl2.$addUrl3;
	$usersNum = $Users_Model->getUsersNum($tel);
	$users = $Users_Model->getUsersForAdmin($sqlSegment, $page, $tel);

	$pageurl =  pagination($usersNum, Option::get('admin_perpage_num'), $page, "popup.php?tableID=user&{$addUrl}pid=");
}

//用户选择弹出窗口
else if ($tableID == 'student') {
	$Student_Model = new Student_Model();

	$tel = isset($_REQUEST['tel']) ? $_REQUEST['tel'] : '';

	$sqlSegment .= ' ORDER BY buildtime DESC ';
	$pwd = '学生';
	$addUrl1 = $tel ? "tel={$tel}&" : '';
	$addUrl2 = $idObj ? "idObj={$idObj}&" : ''	;
	$addUrl3 = $nameObj ? "nameObj={$nameObj}&" : '';
	$addUrl=$addUrl1.$addUrl2.$addUrl3;
	$usersNum = $Student_Model->getStudentsNum($tel);
	$users = $Student_Model->getStudentsForAdmin($sqlSegment, $page, $tel);
	$pageurl =  pagination($usersNum, Option::get('admin_perpage_num'), $page, "popup.php?tableID=student&{$addUrl}pid=");
}
else  {
	$Popup_Model = new Popup_Model();
	$name = isset($_GET['name']) ? $_GET['name'] : '';
	$name = $name?$name:$_POST['name'];
	$pwd="";
	switch ($tableID)
	{
		case "activity":
			$pwd = '活动';
 			break;
		case "card":
			$pwd = '优惠卡';
			break;
		case "course":
			$pwd = '课程';
			break;
		default:
			exit();
	}

	$addUrl1 = $name ? "name={$name}&" : '';
	$addUrl2 = $idObj ? "idObj={$idObj}&" : '';
	$addUrl3 = $nameObj ? "nameObj={$nameObj}&" : '';
	$addUrl4 = $tableID ? "tableID={$tableID}&" : '';
	$addUrl=$addUrl1.$addUrl2.$addUrl3.$addUrl4;

	$popupDataNum = $Popup_Model->getPopupDataNum($tableID,$name);
	$popupDatas = $Popup_Model->getPopupData($tableID,$name,$page);
	$pageurl =  pagination($popupDataNum, Option::get('admin_perpage_num'), $page, "popup.php?{$addUrl}pid=");
}
require_once View::getView('popup/popup');